<% breadcrumb :event_lottery_prize, @event_lottery_prize%>

<div class="row">
  <div class="col-lg-12">
    <div class="ibox float-e-margins">
      <div class="ibox-title">
        <h5>奖项列表设置---<%= @event_lottery_prize.name%></h5>
      </div>
      <div class="ibox-content">
        <div class="row">
          <div class="text-right">
            <%= link_to "添加奖项", new_event_event_lottery_prize_event_lottery_prize_item_path(current_event, @event_lottery_prize), class: "btn btn-white btn-sm"%>
            <%= link_to "抽奖规则设置", event_event_lottery_prize_lottery_prize_rule_path(current_event, @event_lottery_prize), class: "btn btn-white btn-sm"%>
            <button type="button" class="btn btn-white btn-sm" data-toggle="modal" data-target="#myModal">
              查看奖项列表
            </button>
          </div>
          <div class="row">
            <div class="col-md-2">
              <%= link_to "  已中奖", event_event_lottery_prize_path(current_event, @event_lottery_prize, state: 'has_lottery' ) %>
              &nbsp;&nbsp;|&nbsp;&nbsp;
              <%= link_to "全部", event_event_lottery_prize_path(current_event, @event_lottery_prize) %>
            </div>
            <form action=<%= "/app/events/#{current_event.id}/event_lottery_prizes/#{@event_lottery_prize.id}" %> method="get">
              <div class="col-md-3 col-md-offset-6">
                <%= text_field_tag :keyword, params[:keyword], class: "form-control" %>
              </div>
              <button class="btn btn-white" type="submit">搜索</button>
            </form>
          </div>
          <table class="table table-hover table-strip">
            <thead>
              <tr>
                <td>序号</td>
                <td>姓名</td>
                <td>省</td>
                <td>市</td>
                <td>公司</td>
                <td>手机号</td>
                <td>标签</td>
                <td>状态</td>
                <td>奖品</td>
              </tr>
            </thead>
            <tbody>
              <% @attendees.each_with_index do |attendee, index| %>
                <tr>
                  <% lottery_prize = LotteryPrize.search_by_attendee_and_event_lottery_prize(attendee, @event_lottery_prize)%>
                <td><%= index %></td>
                <td><%= attendee.name %></td>
                <td><%= attendee.province %></td>
                <td><%= attendee.city %></td>
                <td><%= attendee.company %></td>
                <td><%= attendee.mobile %></td>
                <td><%= attendee.category.try(:name) %></td>
                <td><%= lottery_prize.present? ? '中奖' : '未中奖' %></td>
                <td><%= lottery_prize.present? ? lottery_prize.first.event_lottery_prize_item.name : '' %></td>
                </tr>
              <% end %>
            </tbody>
          </table>
        </div>
        <div class="row">
          <div class="col-sm-12">
            <%= paginate @attendees %>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="myModalLabel">奖项列表</h4>
      </div>
      <div class="modal-body">
          <table class="table table-striped table-hover">
            <thead>
              <tr>
                <td>#</td>
                <td>奖项名称</td>
                <td>数量</td>
                <td>操作</td>
              </tr>
            </thead>
            <tbody>
              <% @event_lottery_prize_items.each_with_index do |event_lottery_prize_item, index|%>
              <tr>
                <td><%= index %></td>
                <td><%= event_lottery_prize_item.name %></td>
                <td><%= event_lottery_prize_item.count %></td>
                <td>
                  <%= link_to '编辑', edit_event_event_lottery_prize_event_lottery_prize_item_path(current_event, @event_lottery_prize, event_lottery_prize_item), class: 'btn btn-primary btn-xs' %>
                  <%= link_to '指定中奖人管理',event_event_lottery_prize_event_lottery_prize_item_specify_attendee_lottery_path(current_event, @event_lottery_prize, event_lottery_prize_item), class: 'btn btn-primary btn-xs' %>
                  <%= link_to '删除', event_event_lottery_prize_event_lottery_prize_item_path(current_event, @event_lottery_prize, event_lottery_prize_item), method: :delete, data: {confirm: '确定删除?'}, class: 'btn btn-danger btn-xs' %>
                </td>
              </tr>
              <% end %>
            </tbody>
          </table>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-white" data-dismiss="modal">close</button>
      </div>
    </div>
  </div>
</div>
